<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/27
 * Time: 15:40
 */

namespace common\sources\write\businessacount;

use Yii;
use common\models\craftsman\BusinessAccount;

class BusinessAcountAccess implements IBusinessAcountAccess
{
    public function modifyBusAccount($data)
    {
        $sql = 'UPDATE ' . BusinessAccount::tableName() . ' SET total_deposit = :total_deposit,ava_deposit = :ava_deposit,freezing_deposit = :freezing_deposit,ava_pepper = :ava_pepper,freezing_golds = :freezing_golds,update_time = :update_time WHERE bus_id = :bus_id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':total_deposit' => $data['total_deposit'],
                ':ava_deposit' => $data['ava_deposit'],
                ':freezing_deposit' => $data['freezing_deposit'],
                ':ava_pepper' => $data['ava_pepper'],
                ':freezing_golds' => $data['freezing_golds'],
                ':update_time' => time(),
                ':bus_id' => $data['bus_id']
            ])->execute();
    }

    public function modifyAcount($data)
    {
        $sql = 'UPDATE ' . BusinessAccount::tableName() . ' SET ava_deposit = :ava_deposit,freezing_deposit = :freezing_deposit,ava_pepper = :ava_pepper,freezing_golds = :freezing_golds,update_time = :update_time WHERE bus_id = :bus_id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':ava_deposit' => $data['ava_deposit'],
                ':freezing_deposit' => $data['freezing_deposit'],
                ':ava_pepper' => $data['ava_pepper'],
                ':freezing_golds' => $data['freezing_golds'],
                ':update_time' => time(),
                ':bus_id' => $data['bus_id']
            ])->execute();
    }
    //增加充值记录
    public function addAccount($data)
    {
        return Yii::$app->db->createCommand()->insert('business_account', [
            'bus_id' => $data['bus_id'],
            'total_deposit' => isset($data['total_deposit']) ? $data['total_deposit'] : 0,
            'ava_deposit' => isset($data['ava_deposit']) ? $data['ava_deposit'] : 0,
            'create_time' => time()
        ])->execute();
    }
    //提现修改账号信息
    public function withdrawalCash($data)
    {
        $sql = 'UPDATE ' . BusinessAccount::tableName() . ' SET total_deposit = :total_deposit,ava_deposit = :ava_deposit,cash_deposit = :cash_deposit,freezing_deposit = :freezing_deposit,update_time = :update_time WHERE bus_id = :bus_id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':total_deposit' => $data['total_deposit'],
                ':ava_deposit' => $data['ava_deposit'],
                ':cash_deposit' => $data['cash_deposit'],
                ':freezing_deposit' => $data['freezing_deposit'],
                ':update_time' => time(),
                ':bus_id' => $data['bus_id']
            ])->execute();
    }
    //充值花椒
    public function rechargePepper($data)
    {
        $sql = 'UPDATE ' . BusinessAccount::tableName() . ' SET total_deposit = :total_deposit,ava_deposit = :ava_deposit,ava_pepper = :ava_pepper,update_time = :update_time WHERE bus_id = :bus_id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':total_deposit' => $data['total_deposit'],
                ':ava_deposit' => $data['ava_deposit'],
                ':ava_pepper' => $data['ava_pepper'],
                ':update_time' => time(),
                ':bus_id' => $data['bus_id']
            ])->execute();
    }
}